//统包详情
var ItemJson={};//货品详情
var supplierJson={};//供应商详情
var imgs;
var videos;
var supplier;
var RATE=Number($.cookie("ParcelRate"));//汇率
var app_url=location.origin;
var MANAGE_MODE=false;
var MOBILE=true;
var TEAM=0;
var PlaceOrder=false;//代下单
var typeNo_id=0;
(function(){
	//var parcelID= parcel_id;
	var parcelItem={
		init:function(){
			args = GetUrlParms();				
			if(args["ID"]!=undefined){						
				 parcelID = args["ID"];//产品ID					 
			}
			if(args["team"]!=undefined){
				TEAM=args["team"];//2为现货
			}
			if(args["cid"]!=undefined){
				 Customer_id = args["cid"];	
				 PlaceOrder=true;//代下单
			}
            if(args["typeNo"]!=undefined){
                typeNo_id = args["typeNo"];
            }
			this.bindEvent();
			this.loadParcelItem();
		},
		bindEvent:function(){
			var self=this;
            // $("#parcels").on("click", ".item", function() {
             //    var productNo=$(this).attr("data-ProductNo");
             //    console.log("00000000000")
             //    console.log(productNo)
             //    var productSupplier=$(this).attr("data-ProductSupplier");
             //    if(TEAM==0){
             //        self.loadParcelItem(productNo,productSupplier);
             //    }else{
             //        self.loadParcelItem();
             //    }
			// })

			//立即购买
			$("#edit_btn_box").on("click","#add_to_order",function(){
				var orderJson={};
            	orderJson.orderID = [];
				orderJson.type="parcels";
				orderJson.couNum=$('#counts').val();
	            orderJson.orderID.push(parcelID);
	            orderJson.PriceUSD=$("#dataUSD").text();
	            orderJson.PriceRMB=$("#dataRMB").text();


	            if(PlaceOrder==true){
	            	var link_url="/Customer/SubmitDiaOrder?type=2&cid="+Customer_id;
	            }else{
	            	var link_url="/Customer/SubmitDiaOrder?type=2";
	            }	            
	            if(APP){
	            	var appJson={};
	            	appJson.title=_("确认下单");
	            	appJson.url=app_url+link_url;
	            	appJson.content=JSON.stringify(orderJson);
	            	YiYi_APP.submitOrder(JSON.stringify(appJson))
	            }else{
	            	var action=link_url;
				  	form = $("<form method='post' id='params_form' action='"+action+"'>"+
				   	"<input type='text' value='"+JSON.stringify(orderJson)+"' name='params'></form>")
					$("#form_box").html(form);
					$("#params_form").submit();
	            }
			});
			//加入购物车
			$("#edit_btn_box").on("click","#add_to_cart",function(){
				var num=$("#counts").val();
				self.addCart(num);
			});

			//添加数量
			$("body").on('click','#count_adds',function(){
				var num_weight=Number($('#num_weight').text());
				var value=0;
				if(Number($('#counts').val())<1){
					if(num_weight<1){
                        value=num_weight;
					}else {
                        value=1;
					}

				}else {
                    value=Number($('#counts').val())+1;
					if(value>num_weight){
                        value=num_weight;
                        $('.count_msg').show()
					}
				}
                if(String(value).length>5){
                    value=value.toFixed(3);
                }
                $('#counts').val(value);
			});
			//减少数量
			$("body").on('click',"#count_subs",function(){
                var num_weight=Number($('#num_weight').text());
                var num = Number($("#counts").val());
                if(num<2&&num>1){
                    num=1;
                }else {
                    num-=1;
					if(num<=0){
						num=0.001;
					}
				}
                if(String(num).length>5){
                    num=num.toFixed(3);
                }
                $("#counts").val(num);

                if(num<=num_weight){
                    $('.count_msg').hide()
				}
            });
			//继续逛逛
            $(".page").on("click","#go_shop",function(){
            	var linkUrl="/Customer/WhiteParcels?team=0";
            	if(APP){
	           		YiYi_APP.finish();
            	}else{
            		location.href=linkUrl;
            	}
            });
             //去购物车
            $(".page").on("click","#go_cart",function(){
            	var linkUrl="/Customer/ParcelCart";
            	if(APP){
            		var appJson={};
	           		appJson.title=_("购物车");
	           		appJson.function_menu="shopping_cart";
	           		appJson.url=app_url+linkUrl;		           		
	           		YiYi_APP.showExistingPage(JSON.stringify(appJson));
            	}else{
            		location.href=linkUrl;
            	}
            });
			//删除产品
			$("#edit_btn_box").on("click","#parcel_delete",function(){
				myApp.confirm(_('您确定要删除该货品吗？'), function () {
			       self.DelParcels(parcelID);
			   	});					
			});	

			//app编辑
			$("#edit_btn_box").on("click","#edit_btn",function(){
				var url=$(this).attr("data-href");
				//var title=$("#app_title").text();				
				if(APP){
					var editJson={};
					editJson.url=app_url+url;
					editJson.title=_("统包编辑");
					console.log(JSON.stringify(editJson))
					YiYi_APP.editGoods(JSON.stringify(editJson));
				}else{
					location.href =url;
				}
			});

            //添加数量
            $("body").on('click','#count_add',function(){
                var num_weight=parseInt($('#num_weight').text());
                var value=parseInt($('#counts').val())+1;
                if(value>num_weight){
                    value=num_weight;
                    $('.count_msg').show()
                }
                $('#counts').val(value);
            });
            //减少数量
            $("body").on('click',"#count_sub",function(){
                var num_weight=parseInt($('#num_weight').text());
                var num = $("#counts").val()
                if(num>1){
                    $("#counts").val(num-1);
                }
                if(num<=num_weight){
                    $('.count_msg').hide()
                }
            });

		},
		//加入购物车
		addCart:function(num){
			myApp.showPreloader(_('正在加入中，请稍等...'));
			var submitJson={};
			submitJson.CustomerID=CustomerID;
			submitJson.CartType=1;
			submitJson.IDs=parcelID;
			submitJson.InventoryCount=num;
			$.ajax({
				url:"/Team/AddParcelsCart",
				type:"POST",
				data:JSON.stringify(submitJson),
				contentType:"application/json;charset=utf8",
				success:function(result){
					var res=eval('('+result+')');
					myApp.hidePreloader();
					if(res.msgcode==true){
						var strTip = "";
						strTip = '<div class="tip-box order-tip">'+
							'<div class="tip-text">'+
							 	'<div class="tip-title">'+
							 		'<div class="">'+_("加入购物车成功")+'</div>'+
							 	'</div>'+
							 	'<div class="buttons">'+
							 		'<span class="btn-left" id="go_shop"><a href="#">'+_("继续逛逛")+'</a></span>'+
							 		'<span class="btn-right" id="go_cart"><a href="#">'+_("去购物车")+'</a></span>'+
							 	'</div>'+
							'</div>'+
						'</div>';
					$("#app_no_header").after(strTip);
					$(".tip-box").show();
					//   @*主题色start*@
			        $(document.createElement("script")).attr("src","/Js/ThemesColor.js").appendTo("html");
					//  @*主题色end*@
					}else{
						myApp.alert(res.msginfo);
					}
				}
			});
		},
		//加载详情
		loadParcelItem:function(){
		    myApp.showIndicator();//显示加载中
			var das=JSON.parse(localStorage.getItem('das')) || '';

			var self=this;
			var submitJson={};
			submitJson.ID=parcelID;
			submitJson.GoodsType=2;
			if(TEAM==0){
                // if(das){
				// 	console.log(das)
                //     var requsetProduct={};
                //     requsetProduct.ProductNo=das.productno;
                //     requsetProduct.ProductSupplier=das.productsupplier;
                //     requsetProduct.CustomerID=CustomerID;
                //     requsetProduct.GoodsType=2;
                //     console.log(requsetProduct)
                //     $.ajax({
                //         url: "/Customer/ProductSearch",//提交地址
                //         type: "POST",//提交方式
                //         data: JSON.stringify(requsetProduct),
                //         contentType: "application/json; charset=utf-8",
                //         success: function (result) {
				//
                //         }
                //     });
                // };

				submitJson.CustomerID = CustomerID;//客户ID
			}
            if(TEAM ==3){
                submitJson.CustomerID=Customer_id;
            }
			if(TEAM==2){
				submitJson.IsMyStock=true;
			}
			
			$.ajax({
				url:'/Team/GetProductData',
				type:'POST',
				data: JSON.stringify(submitJson),
				dataType:'JSON',
				contentType: "application/json; charset=utf8",
				success:function(result){
					var res=eval('(' + result + ')')
					ItemJson=res;
					if (res.msgcode == true) {
						var datas=res.msginfo.rows;	
						var data =datas[0];				
						// console.log(data[0].Images)
						supplier=data.Supplier;
						//self.LoadSupplierDetail(data.Supplier);
						//显示图片start
						imgs = data.Images.split("|");
						var lis="";
						var app_lis=[];
						var span_lis="";
						imgArray=[];
				        for (var i=0; i< imgs.length;i++) {
				            if (imgs[i].length > 10) {
				                var span_li='<span data-val="'+i+'"></span>';
				                span_lis+=span_li;
				                var li = '<li><a href="'+imgs[i] +'"><img src="' + imgs[i] + '" class="image' + i + '"/></a></li>';
				                lis += li;
				                //app_li='<li data-turn="'+i+'"><a href="#"><img _src="' + imgs[i] + '" src="' + imgs[i] + '" /></a></li>';
				        		//app_lis+=app_li;
				        		var big = imgs[i].replace('800x800', '1920x1920');
				        		imgArray.push(big)
				        		var app_li={url: imgs[i], caption: i};
				        		app_lis.push(app_li);
				            }else{
				            	var img_null='/images/no_img.jpg';
				            	var lis='<li><a href="/images/no_img.jpg"><img src="'+img_null+'" class="image' + i + '"/></a></li>';
				            	var app_li={url: img_null, caption: i};
				        		app_lis.push(app_li);
				            	imgArray.push(img_null)
				            }
				        }

				        //图片列
				        $("#img_box").html(lis);
                        $("#Indicators").html(span_lis);
						if(MOBILE){
							(function(window, Util, PhotoSwipe){
								document.addEventListener('DOMContentLoaded', function(){
									var options = {},
										instance = PhotoSwipe.attach( window.document.querySelectorAll('.ps-carousel-item img'), options );								
								}, false);
								Util.Events.domReady(function(e){									
									var instance, indicators;									
									instance = PhotoSwipe.attach(	
											app_lis,
										{
											target: window.document.querySelectorAll('#PhotoSwipeTarget')[0],
											preventHide: true,
											getImageSource: function(obj){
													return obj.url;
											},
											getImageCaption: function(obj){
												return obj.caption;
											}
										}
									);									
									indicators = window.document.querySelectorAll('#Indicators span');
									instance.addEventHandler(PhotoSwipe.EventTypes.onDisplayImage, function(e){										
										var i, len;
										for (i=0, len=indicators.length; i<len; i++){
											indicators[i].setAttribute('class', '');
										}
										indicators[e.index].setAttribute('class', 'current');										
									});									
									instance.show(0);									
								});								
							}(window, window.Code.Util, window.Code.PhotoSwipe))							
						}
                        //显示图片end
                        //显示视频
                        // $('#video_div').find('source').attr('src',data.Videos)
                        $('#video_div').find('video').attr('src',data.Videos)
                        $('#video_div').find('.zy_wrap').css('height','250px')






						//总价计算
						var parelCount="";
						if(TEAM==0||TEAM==3){
							parelCount= '<div class="tr tr_block">'+
				
							   '<div class="td td_str">'+_("购买重量")+'：</div>'+
							   '<div class="td td_data">'+
								'<div style="float: left;height: 26px"><img id="count_subs" class="count_weight_sub"  src="../../images/X19.png"></div><div style="border: 1px solid #aaaaaa; height: 24px;float: left">';
								if(data.Weight>1){
									parelCount+= '<input style="height: 100%; border: none" class="count_inp"  type="number"  id="counts" onkeyup="parcelNum('+data.Weight+')" value="1">';
								}else{
									parelCount+='<input style="height: 100%;border: none" class="count_inp"  type="number"  id="counts" onkeyup="parcelNum('+data.Weight+')"   value="'+data.Weight+'">';
								}
							parelCount+='</div><div style="float: left;height: 26px"><img id="count_adds"  class="count_weight_add" src="../../images/X20.png"></div>'+
								'<div style="display:inline-block">(库存<p id="num_weight" style="display: inline">'+data.Weight+'</p>CT)</div>'+
								'<div style="color:#ff4400;display:none" class="count_msg">您所购买的重量超过库存重量</div>'+
								'</div>'+
								'</div>';
						}


						var parelPrice="";
						if(TEAM==2){
                            parelPrice+='<div class="detail_left">'+
                                	'<div class="tr">'+
                                '<div class="td td_str">'+_("采购时间")+'：</div>'+
                                	'<div class="td td_data" id="purchaseTime">'+YearDateFormat(data.PurchaseTime)+'</div>'+
                                	'</div>'+
								'<div class="tr">'+
                                '<div class="td td_str">'+_("采购汇率")+'：</div>'+
                                	'<div class="td td_data" >'+data.PurchaseExchange+'</div>'+
                                	'</div>'+
								'</div>'+
                                	'<div class="detail_right">'+
                                '<div class="tr">'+
                                	'<div class="td td_str">'+_("采购供应商")+'：</div>'+
                                	'<div class="td td_data">'+data.PurchaseSupplier+'</div>'+
                                	'</div>'+
                                	'<div class="tr">'+
                                '<div class="td td_str">'+_("付&nbsp;&nbsp;款")+'：</div>'+
                                	'<div class="td td_data">'+formatReceiptStatus(data.ReceiptStatus)+'</div>'+
                                	'</div>'+
                                	'</div>';
                            parelPrice+='<div class="detail_left">'+
                                '<div class="tr">'+

                                '<div class="td td_str">'+_("发货时间")+'：</div>'+
                                '<div class="td td_data" >'+YearDateFormat(data.ShipTime)+'</div>'+
                                '</div>'+
                                '</div>'+
                                '<div class="detail_right">'+
                                '<div class="tr">'+

                                '<div class="td td_str">'+_("到货时间")+'：</div>'+
                                '<div class="td td_data">'+YearDateFormat(data.ArrivalTime)+'</div>'+
                                '</div>'+
                                '</div>';
                            parelPrice+='<div class="detail_left">'+
                                	'<div class="tr CurrentUSD">'+
                                '<div class="td td_str">'+_("原&nbsp;$&nbsp;/Ct")+'：</div>'+
                                	'<div class="td td_data price_color" id="dataUSD">'+returnPerPrice(data)+'</div>'+
                                	'</div>'+
									'<div class="tr CurrentRMB">'+
								'<div class="td td_str">'+_("原￥/Ct")+'：</div>'+
                                	'<div class="td td_data price_color" id="dataRMB">'+returnPerRMBPrice(data)+'</div>'+
                                	'</div>'+
                                	'</div>'+
									'<div class="detail_right">'+
                                	'<div class="tr CurrentUSD">'+
                                '<div class="td td_str">'+_("总原价$")+'：</div>'+
                                	'<div class="td td_data price_color">'+returnPrice(data)+'</div>'+
                                	'</div>'+
                                	'<div class="tr CurrentRMB">'+
                                '<div class="td td_str">'+_("总原价￥")+'：</div>'+
                                	'<div class="td td_data price_color">'+returnRMBPrice(data)+'</div>'+
                                	'</div>'+
                                	'</div>';
                            parelPrice+='<div class="detail_left">'+
                               	 	'<div class="tr CurrentUSD">'+
                                '<div class="td td_str">'+_("采&nbsp;$&nbsp;/Ct")+'：</div>'+
                                	'<div class="td td_data price_color" id="dataUSD">'+returnPurUSDPrice(data)+'</div>'+
                                	'</div>'+
                               	 	'<div class="tr CurrentRMB">'+
                                '<div class="td td_str">'+_("采￥/Ct")+'：</div>'+
                                	'<div class="td td_data price_color" id="dataRMB">'+returnPurRMBPrice(data)+'</div>'+
                                	'</div>'+
                                	'</div>'+
                                	'<div class="detail_right">'+
                                	'<div class="tr CurrentUSD">'+
                                '<div class="td td_str">'+_("总采价$")+'：</div>'+
                                	'<div class="td td_data price_color">'+returnPurUSDPriceAll(data)+'</div>'+
                                	'</div>'+
                                	'<div class="tr CurrentRMB">'+
								'<div class="td td_str">'+_("总采价￥")+'：</div>'+
                                	'<div class="td td_data price_color">'+returnPurRMBPriceAll(data)+'</div>'+
                                	'</div>'+
                                	'</div>';
						}else{
							if(TEAM==0){

                                parelPrice='<div class="detail_left">'
								if(price_td_new==true){
                                    parelPrice+= '<div class="tr CurrentUSD">'+
                                        '<div class="td td_str">'+_("单&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价$")+'：</div>'+
                                        '<div class="td td_data price_color" id="dataUSD">'+returnPerPrice(data)+'</div>'+
                                        '</div>'
								}
                               if(RMBPrice_td_new==true){
                                   parelPrice+= '<div class="tr CurrentRMB">'+
                                       '<div class="td td_str">'+_("单&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价￥")+'：</div>'+
                                       '<div class="td td_data price_color" id="dataRMB">'+returnPerRMBPrice(data)+'</div>'+
                                       '</div>'
							   }


							   //优惠价$/Ct ￥/Ct
                                var parcelPriceDiacount='';
                                parcelPriceDiacount='<div class="detail_left">';
							   	if(discountParcelPrice_per_td_new==true){
                                    parcelPriceDiacount+= '<div class="tr CurrentUSD">'+
                                        '<div class="td td_str">'+_("优&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;惠$/Ct")+'：</div>'+
                                        '<div class="td td_data price_color" id="dataUSD">'+formatUSDPrice(data.Price*Discounts)+'</div>'+
                                        '</div>';
							   	}
							   	if(discountParcelRMBPrice_per_td_new==true){
                                    parcelPriceDiacount+='<div class="tr CurrentRMB">'+
                                        '<div class="td td_str">'+_("优&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;惠￥/Ct")+'：</div>'+
                                        '<div class="td td_data price_color" id="dataRMB">'+formatRMBPrice(data.Price*RATE*Discounts)+'</div>'+
                                        '</div>';
								}


								parelPrice+= '</div><div class="detail_right">'
								if(price_td_new==true){
                                    parelPrice+='<div class="tr CurrentUSD">'+
                                        '<div class="td td_str">'+_("总&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价$")+'：</div>'+
                                        '<div class="td td_data price_color">'+returnPrice(data)+'</div>'+
                                        '</div>'
								}
                                if(RMBPrice_td_new==true){
                                    parelPrice+= '<div class="tr CurrentRMB">'+
                                        '<div class="td td_str">'+_("总&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价￥")+'：</div>'+
                                        '<div class="td td_data price_color">'+returnRMBPrice(data)+'</div>'+
                                        '</div>'
								}

								//优惠价$ ￥
                                parcelPriceDiacount+='</div><div class="detail_right">';
                                if(discountParcelPrice_td_new==true){
                                    parcelPriceDiacount+='<div class="tr CurrentUSD">'+
                                        '<div class="td td_str">'+_("优&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;惠$")+'：</div>'+
                                        '<div class="td td_data price_color">'+formatUSDPrice(parseFloat(data.Price)*parseFloat(data.Weight)*Discounts)+'</div>'+
                                        '</div>'
                                }
                                if(discountParcelRMBPrice_td_new==true){
                                    parcelPriceDiacount+= '<div class="tr CurrentRMB">'+
                                        '<div class="td td_str">'+_("优&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;惠￥")+'：</div>'+
                                        '<div class="td td_data price_color">'+formatRMBPrice((formatRMBPrice(parseFloat(data.Price)*parseFloat(RATE)*Discounts)*parseFloat(data.Weight)))+'</div>'+
                                        '</div>'
                                }

                                parcelPriceDiacount+='</div>'
                                parelPrice+= '</div>'
							}else if(TEAM==1 || TEAM==3){
                                parelPrice='<div class="detail_left">'+
                                    '<div class="tr CurrentUSD">'+
                                    '<div class="td td_str">'+_("单&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价$")+'：</div>'+
                                    '<div class="td td_data price_color" id="dataUSD">'+returnPerPrice(data)+'</div>'+
                                    '</div>'+
                                    '<div class="tr CurrentRMB">'+
                                    '<div class="td td_str">'+_("单&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价￥")+'：</div>'+
                                    '<div class="td td_data price_color" id="dataRMB">'+returnPerRMBPrice(data)+'</div>'+
                                    '</div>'+
                                    '</div>'+
                                    '<div class="detail_right">'+
                                    '<div class="tr CurrentUSD">'+
                                    '<div class="td td_str">'+_("总&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价$")+'：</div>'+
                                    '<div class="td td_data price_color">'+returnPrice(data)+'</div>'+
                                    '</div>'+
                                    '<div class="tr CurrentRMB">'+
                                    '<div class="td td_str">'+_("总&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价￥")+'：</div>'+
                                    '<div class="td td_data price_color">'+returnRMBPrice(data)+'</div>'+
                                    '</div>'+
                                    '</div>'
							}



						}

						var supplierStr="";
						if(TEAM==1 || TEAM ==3){
                            supplierStr= '<div class="tr">'+
                                '<div class="td td_str">供应商：</div>'+
                                '<div class="td td_data">'+(data.Supplier)+'</div>'+
                                '</div>';
						}


						//判断视频
						if(TEAM==2){
							 if(data.Category==1 || data.Category ==2 ){
								var videoStrRight='';
                                 videoStrRight= '<div class="tr tr_normal">'+
									'<div class="td td_str"><img src="/images/imageIcon.png" style="height:20px;width:20px" class="ImgBtn"></div>';
								if(data.Videos){
                                    videoStrRight+= '<div class="td td_str"><img src="/images/videoIcon.png" style="height:18px;width:18px" class="VideoBtn"></div>';
								}
                                 videoStrRight+='</div>';
							 }else{
                                 var videoStrLeft='';
                                 videoStrLeft= '<div class="tr tr_normal">'+
                                     '<div class="td td_str"><img src="/images/imageIcon.png" style="height:20px;width:20px" class="ImgBtn"></div>';
                                 if(data.Videos){
                                     videoStrLeft+= '<div class="td td_str"><img src="/images/videoIcon.png" style="height:18px;width:18px" class="VideoBtn"></div>';
                                 }
                                 videoStrLeft+='</div>';
							 }
						}else{
							var videoStr2='';
                            videoStr2+='<div class="tr" style="width:50%">'+
                                '<div class="td td_str"><img src="/images/imageIcon.png" style="height:20px;width:20px"  class="ImgBtn"></div>';
                            if(data.Videos){

                                videoStr2+= '<div class="td td_data"><img src="/images/videoIcon.png" style="height:20px;width:20px" class="VideoBtn"></div>';
							}
                            videoStr2+=  '</div>';
						}
						//库存详情权限start
							var categoryDetailPower=''; //主石类型
							var weightDetailPower='';//总重
							var shapeDetailPower=''; //形状
							var colorDetailPower='';//颜色
							var placeDetailPower=''; //所在地
							if(TEAM==0){

                                    categoryDetailPower= '<div class="tr">'+
                                        '<div class="td td_str">'+_("主石类型")+'：</div>'+
                                        '<div class="td td_data" id="app_title">'+GetCategory("parcels",data.Category)+'</div>'+
                                        '</div>'

                                    weightDetailPower= '<div class="tr">'+
                                        '<div class="td td_str">'+_("总&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;重")+'：</div>'+
                                        '<div class="td td_data">'+data.Weight+'</div>'+
                                        '</div>'

                                    shapeDetailPower= '<div class="tr">'+
                                        '<div class="td td_str">'+_("形&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;状")+'：</div>'+
                                        '<div class="td td_data">'+GetText("parcels",data.Category,data.Shape,"Shape")+'</div>'+
                                        '</div>'

                                    colorDetailPower='<div class="tr">'+
                                        '<div class="td td_str">'+_("颜&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;色")+'：</div>'+
                                        '<div class="td td_data">'+GetText("parcels",data.Category,data.Color,"Color")+'</div>'+
                                        '</div>'

                                if(place_td_new==true){
                                    placeDetailPower='<div class="tr">'+
                                        '<div class="td td_str">'+_("所&nbsp;在&nbsp;地")+'：</div>'+
                                        '<div class="td td_data">'+GetText("parcels",data.Category,data.Place,"Place")+'</div>'+
                                        '</div>'
                                }
							}else{
									if(TEAM==1 || TEAM==3){
                                        categoryDetailPower= menu_ordering_parcels_Category?'<div class="tr">'+
                                            '<div class="td td_str">'+_("主石类型")+'：</div>'+
                                            '<div class="td td_data" id="app_title">'+GetCategory("parcels",data.Category)+'</div>'+
                                            '</div>':''
									}else if(TEAM==2){
                                        categoryDetailPower= '<div class="tr">'+
                                            '<div class="td td_str">'+_("主石类型")+'：</div>'+
                                            '<div class="td td_data" id="app_title">'+GetCategory("parcels",data.Category)+'</div>'+
                                            '</div>'
									}

									if(TEAM==1 || TEAM==3){
                                        weightDetailPower= menu_ordering_parcels_Weight?'<div class="tr">'+
                                            '<div class="td td_str">'+_("总&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;重")+'：</div>'+
                                            '<div class="td td_data">'+data.Weight+'</div>'+
                                            '</div>':''
									}else if(TEAM==2){
                                        weightDetailPower= '<div class="tr">'+
                                            '<div class="td td_str">'+_("总&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;重")+'：</div>'+
                                            '<div class="td td_data">'+data.Weight+'</div>'+
                                            '</div>'
									}

									if(TEAM==1 || TEAM==3){
                                        shapeDetailPower= menu_ordering_parcels_Shape?'<div class="tr">'+
                                            '<div class="td td_str">'+_("形&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;状")+'：</div>'+
                                            '<div class="td td_data">'+GetText("parcels",data.Category,data.Shape,"Shape")+'</div>'+
                                            '</div>':''
									}else if(TEAM==2){
                                        shapeDetailPower= '<div class="tr">'+
                                            '<div class="td td_str">'+_("形&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;状")+'：</div>'+
                                            '<div class="td td_data">'+GetText("parcels",data.Category,data.Shape,"Shape")+'</div>'+
                                            '</div>'
									}

									if(TEAM==1 || TEAM==3){
                                        colorDetailPower=menu_ordering_parcels_Color?'<div class="tr">'+
                                            '<div class="td td_str">'+_("颜&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;色")+'：</div>'+
                                            '<div class="td td_data">'+GetText("parcels",data.Category,data.Color,"Color")+'</div>'+
                                            '</div>':''
									}else if(TEAM==2){
                                        colorDetailPower='<div class="tr">'+
                                            '<div class="td td_str">'+_("颜&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;色")+'：</div>'+
                                            '<div class="td td_data">'+GetText("parcels",data.Category,data.Color,"Color")+'</div>'+
                                            '</div>'
									}

                                   if(TEAM==1 || TEAM==3){
                                       placeDetailPower=menu_ordering_parcels_Place?'<div class="tr">'+
                                           '<div class="td td_str">'+_("所&nbsp;在&nbsp;地")+'：</div>'+
                                           '<div class="td td_data">'+GetText("parcels",data.Category,data.Place,"Place")+'</div>'+
                                           '</div>':''
								   }else{
                                       placeDetailPower='<div class="tr">'+
                                           '<div class="td td_str">'+_("所&nbsp;在&nbsp;地")+'：</div>'+
                                           '<div class="td td_data">'+GetText("parcels",data.Category,data.Place,"Place")+'</div>'+
                                           '</div>'
								   }

							}


                        //库存详情权限end

						//详情参数
						var parcels_detail=[
						'<div class="detail_left">',

                            categoryDetailPower,
		 					'<div class="tr">',
			   				 	'<div class="td td_str">'+_("货&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号")+'：</div>', 
			   				 	'<div class="td td_data">',data.OriginSN,'</div>',
			 				'</div>',
							shapeDetailPower,
                            colorDetailPower,
							placeDetailPower,
                            videoStrLeft,

			 			'</div>',
			 			'<div class="detail_right">',
			 				'<div class="tr">',
			 				 	'<div class="td td_str">'+_("大&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;小")+'：</div>',
			   				 	'<div class="td td_data">',data.Size,'</div>',
			 				'</div>',
							weightDetailPower,
			 				 GetData(data),supplierStr,
                            '<div class="tr tr_normal">',
								'<div class="td td_str">'+_("备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注")+'：</div>',
								'<div class="td td_data">',data.Descript,'</div>',
                            '</div>',
                              videoStrRight,

						 '</div>',
						'<div class="tr  exchangeRate" style="width:50%">',
							'<div class="td td_str">'+_("汇&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;率")+'：</div>',
							'<div class="td td_data">',RATE,'</div>',
						'</div>',

                            videoStr2,
						'<div class="tr tr_normal">',
						'<div class="td td_str">'+_("上传时间")+'：</div>',
						'<div class="td td_data">', DateTimeFormat(data.InsertTime), '</div>',
						'</div>',

						parelPrice,
						parcelPriceDiacount,
						 parelCount
			   				].join('');
						$("#parcels_detail").html(parcels_detail);
						currentShow();  //币种设置
						//$("#img_js").html('<script src="../js/jquery.ad-gallery.js"></script><script src="../js/galler_pic.js"></script>');
           				// var slide='<script type="text/javascript"> TouchSlide({slideCell: "#focus", titCell: ".hd ul", mainCell: ".bd ul",effect: "left",autoPlay: true,autoPage: true, switchLoad: "_src",}) <\/script>';						
						
						//$("#app_js").html(slide);
						$('.item_detail_btn_box').html("");
                        var addCart;
                        if(typeNo_id==0){
                            addCart='';
                        }else{
                            addCart= '<a href="#" style="margin-right:20px;" id="add_to_cart" data-id='+data.ID+'>加入购物车</a>'
                        }
                        var editHtmlStr= [
                            addCart,
							'<a href="#" id="add_to_order">'+_("立即购买")+'</a>'].join('');
                        var placeHtmlStr= ['<a href="#" id="add_to_order">'+_("代购买")+'(<b style="font-size:12px" id="_realName">'+getUrlParam('userName')+'</b>)'+'</a>'].join('');
						var myEditHtml=[        
							'<a href="#" id="edit_btn" data-href="/Team/ParcelManagement?ID=',data.ID,'&type=2&team=',TEAM,'" style="margin-right:20px;">'+_("编辑")+'</a>',
							'<a id="parcel_delete" href="#">'+_("删除")+'</a>'].join('');
							if(TEAM==0){//客户端的列表页
								$("#edit_btn_box").html(editHtmlStr);
							}else if(TEAM==2){//现货
								$("#edit_btn_box").html(myEditHtml);
							}else if(TEAM==3){//代下单
								$("#edit_btn_box").html(placeHtmlStr);
							}
							//   @*主题色start*@
			                $(document.createElement("script")).attr("src","/Js/ThemesColor.js").appendTo("html");
							//  @*主题色end*@
							 //放大图片
							var myPhotoBrowserStandalone = myApp.photoBrowser({
							    photos : imgArray,
							    backLinkText: _('返回'),
							    ofText:"/",
							});
							$$('#look_img').on('click',function () {
								var index=$("#Indicators").find("span.current").index();
								if(APP){
									var ProductImg={};
									 ProductImg['images']=imgArray;
									 ProductImg['index']=index;
									YiYi_APP.showImages(JSON.stringify(ProductImg));
								}else{								
							    	myPhotoBrowserStandalone.open(index);
							   }
							});		
							
					}else{
						myApp.alert(res.result);
					}
					myApp.hideIndicator();//隐藏加载中
				},
				error:function(a,b,c){
					myApp.alert(c);
				}
				
			});
		},
		//刪除统包
		DelParcels:function() {
		    myApp.showIndicator();//显示加载中
			//var adress='/Team/DeleteParcel' + parcelID;
	        $.ajax({
	            url: "/Team/DelProductData",//提交地址
                type: "POST",//提交方式
                data: "{'id':'" +parcelID + "','GoodsType':'2'}",
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var jsonResult = eval('(' + result + ')');//eval()解析单个json对象
	                if (jsonResult && jsonResult.result) {
	                	 myApp.alert(_('删除成功！'), function () {
	                	 	if(APP){	                	 		
			            		YiYi_APP.finish();
	                	 	}else{
	                	 		location.href = "/Team/MyParcel?team=2";
	                	 	}
					    });	       	   	                	
	                } else {
	                    myApp.alert(jsonResult.msg);
	                }
	                myApp.hideIndicator();//隐藏加载中
	            }
	        });
		},	
	}
	parcelItem.init();
}());

//无权限看到价格时的显示
function returnPerPrice(data){
	return formatUSDPrice(data.Price);
}
function returnPerRMBPrice(data){
	return formatRMBPrice(data.Price*RATE);
}
function returnPrice(data){
		return formatUSDPrice((data.Price)*(data.Weight));
}
function returnRMBPrice(data){
	return formatRMBPrice((data.Price*RATE)*(data.Weight));
}

//现货看到的采购单价和总价
function returnPurUSDPrice(data){
    return formatUSDPrice(data.PurchaseUSD);

}

function returnPurRMBPrice(data){
    return formatRMBPrice(data.PurchaseRMB);

}

function returnPurUSDPriceAll(data){
    return formatUSDPrice((data.PurchaseUSD)*(data.Weight));

}

function returnPurRMBPriceAll(data){
    return formatRMBPrice((data.PurchaseRMB)*(data.Weight));

}

//app分享用的详情
function Item_APP(){
	if(APP){
		var shareJson={};
		shareJson.title=_("统包")+GetCategory(ItemJson.Category);
		shareJson.text=_("颜色")+"："+GetText(ItemJson.Category,ItemJson.Color,"Color")+"；"+_("形状")+"："+GetText(ItemJson.Category,ItemJson.Shape,"Shape")+"；"+
		_("大小")+"："+ItemJson.Size+"；"+_("价格")+"："+ItemJson.Price+"；"+_("所在地")+"："+GetText(ItemJson.Category,ItemJson.Place,"Place");
		imgs = ItemJson.Images.split("|");
		shareJson.images=[];
		 for (var i=0; i< imgs.length;i++) {
			if (imgs[i].length > 10) {
				shareJson.images.push(imgs[i]);
			}
		}
		 shareJson.url=app_url+"/"+LANGCODE+"/parcels/"+ItemJson.ID;
		 shareJson.copy_text=shareJson.text;
		YiYi_APP.share(JSON.stringify(shareJson));
	}
}

function GetData(data){
	var type=data.Category;
	var htmlString=[];
	if(type==1 || type==2){
		if(TEAM==0){
                htmlString=[
                    '<div class="tr">',
                    '<div class="td td_str">净&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;度：</div>',
                    '<div class="td td_data">',data.Clarity,'</div>',
                    '</div>'
                ].join('')

		}else{
            htmlString=[
                '<div class="tr">',
                '<div class="td td_str">净&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;度：</div>',
                '<div class="td td_data">',data.Clarity,'</div>',
                '</div>'].join('')
		}

	}
	return htmlString;
}

//购买数量不能大于库存
function parcelNum(num){
	var counts=$("#counts").val();
	if(counts>num){
		$("#counts").val(num);
		$(".count_msg").show();
	}else{
        $(".count_msg").hide();
	}
}

function formatReceiptStatus(val){
    if(val==0){
        return _("未支付");
    }else if(val==1){
        return _("已支付");
    }
}

//点击视频
$("#parcels_detail").on('click','.VideoBtn',function(){
	$("#video_div").show().css("display","block");
    $('#MainContent').hide();
    $("#look_img").hide();
})

// 点击图片icon
$("#parcels_detail").on("click",".ImgBtn",function(){
    $('#MainContent').show();
    $("#look_img").show();
    $("#video_div").hide();

});


